/**
 * @Author: 魏巍 <jswei>
 * @Date:   2018-08-10T21:00:07+08:00
 * @Email:  524314430@qq.com
 * @Filename: mutations.js
 * @Last modified by:   jswei
 * @Last modified time: 2018-08-28T04:33:41+08:00
 * @Copyright: free
 */

import {
    HIDE_LOADING,
    SHOW_LOADING,
    SET_LOGIN,
    SHOW_HEADER,
    SHOW_FOOTER,
    HIDE_HEADER,
    HIDE_FOOTER,
    UPDATE_DIRECTION,
    UPDATE_SITE_CONFIG,
    UPDATE_NAVIGATER_BACK,
    CATCH_ARTICLE
  } from './mutation-type'

  const state = {
    loading: false,
    logined: null,
    header: true,
    footer: true,
    navigater: null,
    site: null,
    navigaterBack: null,
    article: {}
  };

  const mutations = {
    /*loading*/
    [HIDE_LOADING](state) {
      state.loading = false;
    },
    [SHOW_LOADING](state) {
      state.loading = true;
    },
    [SET_LOGIN](state, userInfo) {
      state.logined = userInfo;
    },
    [SHOW_HEADER](state) {
      state.header = true
    },
    [SHOW_FOOTER](state) {
      state.footer = true
    },
    [HIDE_HEADER](state) {
      state.header = false
    },
    [HIDE_FOOTER](state) {
      state.footer = false
    },
    [UPDATE_DIRECTION](state, direction) {
      state.navigater = direction;
    },
    [UPDATE_SITE_CONFIG](state, config) {
      state.site = config;
    },
    [UPDATE_NAVIGATER_BACK](state, status) {
      state.navigaterBack = status
      localStorage.setItem('isBack', status);
    },
    [CATCH_ARTICLE](state, article) {
      state.article = article;
    }
  };

  const getters = {
    getLoadingState(state) {
      return state.loading;
    },
    getLoginedState(state) {
      return state.logined;
    },
    getHeaderState(state) {
      return state.header;
    },
    getFooterState(state) {
      return state.footer;
    },
    getSiteState(state) {
      return state.site;
    },
    getNavigaterBackState(state) {
      return state.navigaterBack;
    },
    getArticleState(state) {
      return state.article;
    }
  };

  export default {
    state,
    mutations,
    getters
  }
